package com.tz.springmvc.sysmanage.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tz.springmvc.sysmanage.entity.User;
import com.tz.springmvc.sysmanage.mapper.UserMapper;
import com.tz.springmvc.sysmanage.service.IUserService;

@Service
public class UserService implements IUserService{

	@Autowired
	private UserMapper userMapper;

	@Override
	public boolean login(String loginName, String password) {
		boolean flag = false;
		List<User> userList = new ArrayList<User>();
		User user = new User();
		user.setLoginName(loginName);
		user.setPassword(password);;
		userList = this.userMapper.getUserList(user);
		if(userList.size()>0){
			flag = true;
		}		
		return flag;
	}

 	public List<User> getUserList(User user) {
		return this.userMapper.getUserList(user);
	}

	@Override
	public boolean addUser(User user) {
		boolean flag = false;
		int rows = this.userMapper.addUser(user);
		if(rows>0){
			flag = true;
		}
		return flag;
	}
	
	@Override
	public boolean delUser(Long userId) {
		boolean flag = false;
		int rows = this.userMapper.delUser(userId);
		if(rows>0){
			flag = true;
		}
		return flag;
	}

	@Override
	public User getUserById(Long userId) {
		return this.userMapper.getUserById(userId);
	}

	@Override
	public boolean updateUser(User user) {
		boolean flag = false;
		int rows = this.userMapper.updateUser(user);
		if(rows>0){
			flag = true;
		}
		return flag;
	}
	
	public boolean updateUserBatch(List<User> userList){
		boolean flag = false;
		int rows = this.userMapper.updateUserBatch(userList);
		if(rows>0){
			flag = true;
		}
		return flag;
	}


}
